putProperty

abstract fun putProperty(name: String, @Nullable value: Any): Boolean

Creates a new property with the given name or updates the existing one in the current JavaScript object and returns true if the property with the given name was created or updated successfully.

The type mapping rules are the following:


| Java               | JavaScript                    |
|--------------------|-------------------------------|
| Number             | Double                        |
| String             | String                        |
| Boolean            | Boolean                       |
| null               | null                          |
| JsObject           | Object                        |
| Node               | Node                          |
| List<?>            | Array or Proxy Object         |
| Set<?>             | Set or Proxy Object           |
| Map<?,?>           | Map or Proxy Object           |
| byte[]             | ArrayBuffer                   |
| Object             | Proxy Object                  |

If you pass a non-primitive Java object to JavaScript, it will be converted into a "proxy" JavaScript object. Method and property calls to this object will be delegated to the Java object. For security reasons, JavaScript can access only those methods and fields of the injected Java object that are explicitly marked as accessible either using the JsAccessible annotation or via the JsAccessibleTypes class.

Java collections that are not made accessible to JavaScript using the JsAccessible annotation or via the JsAccessibleTypes class are converted to JavaScript collections. The content of the converted collection is a deep copy of the Java collection. Modifications of the converted collection in JavaScript do not affect the collection in Java.

Java collections that are made accessible to JavaScript using the JsAccessible annotation or via the JsAccessibleTypes class are wrapped into a JavaScript proxy object. Such proxy objects can be used to modify the collection in Java.

Return

true when property was created or updated successfully

Parameters

name

a string that represents the property name

value

a new value associated with the property with the given name

Throws

when value is a JsObject from a different web page or frame

when the JavaScript object is already disposed or invalid